package com.bwei.like.mynewstop;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import com.bwei.like.mynewstop.Bean.NewsTitleRoot;
<<<<<<< 77331352d74e6afdfbbeaccca4370d33ffbea935
=======
import com.bwei.like.mynewstop.activity.BaseActivity;
>>>>>>> NewsTop
import com.bwei.like.mynewstop.app.MyApplication;
import com.bwei.like.mynewstop.base.BaseData;
import com.bwei.like.mynewstop.utils.CommonUtils;
import com.bwei.like.mynewstop.utils.URLUtils;
import com.google.gson.Gson;

import org.xutils.common.util.LogUtil;

<<<<<<< 77331352d74e6afdfbbeaccca4370d33ffbea935
public class LaunchActivity extends AppCompatActivity {
=======
public class LaunchActivity extends BaseActivity {
>>>>>>> NewsTop


    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            startActivity(new Intent(LaunchActivity.this,MainActivity.class));
            handler.removeCallbacksAndMessages(null);
            finish();
        }
    };
    @Override
<<<<<<< 77331352d74e6afdfbbeaccca4370d33ffbea935
    protected void onCreate(Bundle savedInstanceState) {
=======
    public void onCreate(Bundle savedInstanceState) {
>>>>>>> NewsTop
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launch);

        handler.sendEmptyMessageDelayed(0,3000);


       BaseData baseData = new BaseData() {
            @Override
            public void setResultData(String path) {
                //首先判断文件中是都有数据，如果有数就不进行保存，如果没有则继续请求数据
                if (!TextUtils.isEmpty(CommonUtils.getSp("myChannel"))){
                    return;
                }

                /**
                 * 将数据分开分别存进sheard文件中
                 */
                Gson gson = new Gson();
                NewsTitleRoot newsTitleRoot = gson.fromJson(path, NewsTitleRoot.class);
                StringBuilder stringBuilder1 = new StringBuilder();
                stringBuilder1.append("推荐:, ");
                for (int i = 0; i < 20; i++) {
                    NewsTitleRoot.DataBean.MyDataBean myDataBean = newsTitleRoot.getData().getData().get(i);
                    String category = myDataBean.getCategory();
                    String name = myDataBean.getName();
                    stringBuilder1.append(name+":"+category+",");
                }
                //保存我的频道数据
                CommonUtils.saveSp("myChannel",stringBuilder1.toString());

                StringBuilder stringBuilder2 = new StringBuilder();
                for (int i = 20; i < newsTitleRoot.getData().getData().size(); i++) {
                    NewsTitleRoot.DataBean.MyDataBean myDataBean = newsTitleRoot.getData().getData().get(i);
                    String category = myDataBean.getCategory();
                    String name = myDataBean.getName();
                    stringBuilder2.append(name+":"+category+",");
                }
                //保存更多平道的数据
                CommonUtils.saveSp("moreChannel",stringBuilder2.toString());
            }

            @Override
            protected void setFailResult(int error_Net) {

            }
        };
        baseData.getData(URLUtils.URL_TITLE_PATH,BaseData.LONGTTIME);


        //将解析的默认第一条数据也就是推荐的数据缓存下来
        BaseData baseData1 = new BaseData() {
            @Override
            public void setResultData(String path) {

            }

            @Override
            protected void setFailResult(int error_Net) {

            }
        };
        baseData1.getData(URLUtils.URL_CATEGROY_PATH+"",BaseData.LONGTTIME);
        LogUtil.i(URLUtils.URL_CATEGROY_PATH+"");
        //将解析的默认第一条数据也就是热点的数据缓存下来
        BaseData baseData2 = new BaseData() {
            @Override
            public void setResultData(String path) {

            }

            @Override
            protected void setFailResult(int error_Net) {

            }
        };
        baseData2.getData(URLUtils.URL_CATEGROY_PATH+"news_hot",BaseData.LONGTTIME);
    }
}
